function checkdata() {
	if (!checkUserName(staffadd.username.value)) return false;	if (!checkjob(staffadd.job.value)) return false;
	if (!checkName(staffadd.name.value)) return false;
	if (!checkid(staffadd.idcard.value)) return false;
	return true;
}

function checkPassWord2(pw2) {
	if( staffadd.pwd2.value =="" ) {
		//alert("\请输入密码确认！");
		document.getElementById("password2Err").innerHTML = "<font color = 'red'>Please input the Confirm Password！</font>";
		staffadd.password2.focus();
		return false;
		}
	if( staffadd.pwd2.value != staffadd.password.value ) {
		//alert("\两次密码输入不一致！");
		document.getElementById("password2Err").innerHTML = "<font color = 'red'>Password and Confirm Password must be same！</font>";
		staffadd.password.focus();
		return false;
		}
	document.getElementById("password2Err").innerHTML = "";
	return true;
}
function checkPassWord(pw) {
	if( strlen(staffadd.password.value)<3 || strlen(staffadd.password.value)>40 ) {
		//alert("\正确地登录密码长度为3～40位，仅可用英文、数字、特殊字符！");
		document.getElementById("passwordErr").innerHTML = "<font color = 'red'>Password's length is 3 to 40！</font>";
		staffadd.password.focus();
		return false;
		}
	if( strlen2(staffadd.password.value) ) {
		//alert("\您的密码中包含了非法字符，仅可用英文、数字、特殊字符！");
		document.getElementById("passwordErr").innerHTML = "<font color = 'red'>Password contains illegal characters！</font>";
		staffadd.password.focus();
		return false;
		}
	if( staffadd.password.value == staffadd.username.value ) {
		//alert("\用户名和密码不能相同！");
		document.getElementById("passwordErr").innerHTML = "<font color = 'red'>Username and Password cannot be same！</font>";
		staffadd.password.focus();
		return false;
		}
	document.getElementById("passwordErr").innerHTML = "";
	return true;
}

function checkUserName(ssn){
	if( ssn.length<3 || ssn.length>40 ) {
		//alert("\请输入正确的用户名,用户名长度为3～40位！");
		document.getElementById("usernameErr").innerHTML = "<font color = 'red'>Username's length is 3 to 40！</font>";
		staffadd.username.focus();
		return false;
	}
	if (isWhiteWpace(ssn)){
		//alert("\请输入正确的用户名,用户名中不能包含空格！");
		document.getElementById("usernameErr").innerHTML = "<font color = 'red'>Username cannot contains space！</font>";
		staffadd.username.focus();
		return false;
	}
	if (!isSsnString(ssn)){
		//alert("\对不起，您选择的用户名不正确！用户名\n由a～z的英文字母(不区分大小写)、0～9的数字、点、减\n号或下划线组成，长度为3～40个字符，只能以数字或字母\n开头和结尾,例如：beijing2008，beijing.2008。");
		document.getElementById("usernameErr").innerHTML = "<font color = 'red'>Username contains illegal characters！</font>";
		staffadd.username.focus();
		return false;
	}
	document.getElementById("usernameErr").innerHTML = "";
	return true;
}

function checkjob(ujob){
	if( ujob.length>3 || ujob.length<1 ) {
		//alert("\请输入正确的job,job长度为1~3位！");
		document.getElementById("jobErr").innerHTML = "<font color = 'red'>Job's length is 1 to 3！</font>";
		staffadd.job.focus();
		return false;
	}
	if (isWhiteWpace(ujob)){
		//alert("\请输入正确的job,job中不能包含空格！");
		document.getElementById("jobErr").innerHTML = "<font color = 'red'>Job cannot contains space！</font>";
		staffadd.job.focus();
		return false;
	}
	for(a = 0;a<ujob.length;a++) {
		if(ujob.charAt(a) > 'z' || ujob.charAt(a) <'A' ) {
			//alert("\请输入正确的job,job中只能為英文！");
			document.getElementById("jobErr").innerHTML = "<font color = 'red'>Please input English！</font>";
			staffadd.job.focus();
			return false;
		}
	}
	document.getElementById("jobErr").innerHTML = "";
	return true;
}

function checkName(sn){
	if( sn.length<3 || sn.length>40 ) {
		//alert("\请输入正确的名字,名字长度为3～40位！");
		document.getElementById("nameErr").innerHTML = "<font color = 'red'>Name's length is 3 to 40！</font>";
		staffadd.name.focus();
		return false;
	}
	document.getElementById("nameErr").innerHTML = "";
	return true;
}

function checkid(userid){
	if( userid.length != 8) {
		//alert("\请输入正确的id,id长度为8位！");
		document.getElementById("idErr").innerHTML = "<font color = 'red'>id's length must be 8！</font>";
		staffadd.idcard.focus();
		return false;
	}
	if (isWhiteWpace(userid)){
		//alert("\请输入正确的id,id中不能包含空格！");
		document.getElementById("idErr").innerHTML = "<font color = 'red'>id cannot contains space！</font>";
		staffadd.idcard.focus();
		return false;
	}
	for(a = 0;a<userid.length;a++) {
		if(userid.charAt(a) > '9' || userid.charAt(a) <'0' ) {
			//alert("\请输入正确的id,id中只能為數字！");
			document.getElementById("idErr").innerHTML = "<font color = 'red'>id must be number！</font>";
			staffadd.idcard.focus();
			return false;
		}
	}
	document.getElementById("idErr").innerHTML = "";
	return true;
}

function checkmgr(Mgr){
	if( Mgr.length != 8) {
		//alert("\请输入正确的Manager id,Manager id长度为8位！");
		document.getElementById("managerErr").innerHTML = "<font color = 'red'>Manager's length must be 8！</font>";
		staffadd.mgr.focus();
		return false;
	}
	if (isWhiteWpace(Mgr)){
		//alert("\请输入正确的Manager id,Manager id中不能包含空格！");
		document.getElementById("managerErr").innerHTML = "<font color = 'red'>Manager cannot contains space！</font>";
		staffadd.mgr.focus();
		return false;
	}
	for(a = 0;a<Mgr.length;a++) {
		if(Mgr.charAt(a) > '9' || Mgr.charAt(a) <'0' ) {
			//alert("\请输入正确的Manager id,Manager id中只能為數字！");
			document.getElementById("managerErr").innerHTML = "<font color = 'red'>Manager must be number！</font>";
			staffadd.mgr.focus();
			return false;
		}
	}
	document.getElementById("managerErr").innerHTML = "";
	return true;
}

function checkdeptno(userdeptno){
	if( userdeptno.length >2 || userdeptno.length <1) {
		//alert("\请输入正确的Department No,Department No长度为1~2位！");
		document.getElementById("departmentnoErr").innerHTML = "<font color = 'red'>Department No's length is 1 to 2！</font>";
		staffadd.deptno.focus();
		return false;
	}
	if (isWhiteWpace(userdeptno)){
		//alert("\请输入正确的Department No,Department No中不能包含空格！");
		document.getElementById("departmentnoErr").innerHTML = "<font color = 'red'>Department No cannot contains space！</font>";
		staffadd.deptno.focus();
		return false;
	}
	for(a = 0;a<userdeptno.length;a++) {
		if(userdeptno.charAt(a) > '9' || userdeptno.charAt(a) <'0' ) {
			//alert("\请输入正确的Department No,Department No中只能為數字！");
			document.getElementById("departmentnoErr").innerHTML = "<font color = 'red'>Department No must be number！</font>";
			staffadd.deptno.focus();
			return false;
		}
	}
	document.getElementById("departmentnoErr").innerHTML = "";
	return true;
}

function checksal(Sal){
	if( Sal == "" ) {
		//alert("\请输入正确的Salary,Salary不能為空！");
		document.getElementById("salaryErr").innerHTML = "<font color = 'red'>Please input Salary！</font>";
		staffadd.sal.focus();
		return false;
	}
	if (isWhiteWpace(Sal)){
		//alert("\请输入正确的Salary,Salary中不能包含空格！");
		document.getElementById("salaryErr").innerHTML = "<font color = 'red'>Salary cannot contains space！</font>";
		staffadd.sal.focus();
		return false;
	}
	for(a = 0;a<Sal.length;a++) {
		if(Sal.charAt(a) > '9' || Sal.charAt(a) <'0' ) {
			//alert("\请输入正确的Salary,Salary中只能為數字！");
			document.getElementById("salaryErr").innerHTML = "<font color = 'red'>Salary must be number！</font>";
			staffadd.sal.focus();
			return false;
		}
	}
	document.getElementById("salaryErr").innerHTML = "";
	return true;
}

function checkphone(pphone){
	if( pphone.length != 8) {
		alert("\Phone's length must be 8！");
		staffadd.phone.focus();
		return false;
	}
	if (isWhiteWpace(pphone)){
		alert("\Phone cannot contains space！");
		staffadd.phone.focus();
		return false;
	}
	for(b = 0;b<pphone.length;b++) {
		if(pphone.charAt(b) > '9' || pphone.charAt(b) <'0' ) {
			alert("\Phone must be number！");
			staffadd.phone.focus();
			return false;
		}
	}
	return true;
}

function checkaddress(address){
	if( address.length<3 || address.length>40 ) {
		alert("\Address's length is 3 to 40！");
		staffadd.addr.focus();
		return false;
	}
	if (isWhiteWpace(address)){
		alert("\Address cannot contains space！");
		staffadd.addr.focus();
		return false;
	}
	if (!isSsnString(address)){
		alert("\Address contains illegal characters");
		staffadd.addr.focus();
		return false;
	}
	return true;
}

function strlen(str){
	var len;
	var i;
	len = 0;
	for (i=0;i<str.length;i++){
		if (str.charCodeAt(i)>255) len+=2; else len++;
	}
	return len;
}

function strlen2(str) {
	var len;
	var i;
	len = 0;
	for (i=0;i<str.length;i++){
		if (str.charCodeAt(i)>255) return true;
	}
	return false;
}

function isWhiteWpace (s) {
	var whitespace = " \t\n\r";
	var i;
	for (i = 0; i < s.length; i++){   
		var c = s.charAt(i);
		if (whitespace.indexOf(c) >= 0) {
			return true;
		}
	}
   return false;
}

function isSsnString (ssn)
{
	var re=/^[0-9a-z][\w-.]*[0-9a-z]$/i;
	if(re.test(ssn))
		return true;
	else
		return false;
}
/*
 * function checkssn(gotoURL) { var ssn=staffadd.username.value.toLowerCase();
 * if (checkUserName(ssn)){ var open_url = gotoURL + "?username=" + ssn;
 * window.open(open_url,'','status=0,directories=0,resizable=0,toolbar=0,location=0,scrollbars=0,width=390,height=260'); } }
 */
